﻿Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Unity
Imports Microsoft.Practices.Composite.Regions
Imports Hinshelwood.TFSStickyBuddy.Infrastructure
Imports Infragistics.Windows.Ribbon
Imports Hinshelwood.TFSStickyBuddy.Modules.Model

'Imports StockTraderRI.Infrastructure.Interfaces
'Imports StockTraderRI.Modules.News.Article
'Imports StockTraderRI.Modules.News.Controllers
'Imports StockTraderRI.Modules.News.Services

Public Class CodeplexProjectModule
    Implements IModule

    Private ReadOnly m_container As IUnityContainer
    Private ReadOnly m_rmShell As IRegionManager
    Private ReadOnly m_NavigationService As INavigationService
    Private ReadOnly m_Project As CodePlexProject

    Public Sub New(ByVal container As IUnityContainer, ByVal regionManager As IRegionManager, ByVal navigationService As INavigationService)
        m_container = container
        m_rmShell = regionManager
        m_NavigationService = navigationService
        m_Project = New CodePlexProject("TFS Sticky Buddy", "TFSStickyBuddy", New Uri("https://tfs05.codeplex.com:433"))
    End Sub


    Public Sub Initialize() Implements Microsoft.Practices.Composite.Modularity.IModule.Initialize
        RegisterViewsAndServices()
        RegisterMenuItems()
        'Dim controller As IFeedbackController = m_container.Resolve(Of IFeedbackController)()
        'controller.Run()
    End Sub

    Protected Sub RegisterViewsAndServices()
        m_container.RegisterType(Of ICodeplexProjectController, CodeplexProjectController)(New ContainerControlledLifetimeManager())

    End Sub

    Protected Sub RegisterMenuItems()
        ' m_NavigationService.RegisterTabRegion(RegionNames.CodeplexProject_Tab, "Project")
        ' m_NavigationService.RegisterRibbonGroup(RegionNames.CodeplexProject_Tab_GroupFeedback, "Feedback", RegionNames.CodeplexProject_Tab)
        m_NavigationService.AddSeparatorTool()
        m_NavigationService.RegisterMenuTool(RegionNames.CodeplexProject_AppMenu_Feedback, "Feedback")
        m_NavigationService.RegisterMenuTool(RegionNames.CodeplexProject_AppMenu_Help, "Help")

        Dim controller As ICodeplexProjectController = m_container.Resolve(Of ICodeplexProjectController)()
        ' Add feedback items
        m_NavigationService.AddLabelTool("Send feedback about this application.", RegionNames.CodeplexProject_AppMenu_Feedback)

        Dim newIssueTool As New ButtonTool
        newIssueTool.Caption = "Submit issue"
        newIssueTool.LargeImage = GteImage(New Uri("/Hinshelwood.TFSStickyBuddy.Modules.CodeplexProject;component/Resources/Images/issue.gif", UriKind.Relative))
        newIssueTool.Command = controller.NotImplementedCommand
        newIssueTool.CommandParameter = Nothing
        MenuToolBase.SetMenuItemDescription(newIssueTool, "Submit an issue about this application")
        m_NavigationService.AddTool(newIssueTool, RegionNames.CodeplexProject_AppMenu_Feedback)

        Dim newFeatureTool As New ButtonTool
        newFeatureTool.Caption = "Submit feature request"
        newFeatureTool.LargeImage = GteImage(New Uri("/Hinshelwood.TFSStickyBuddy.Modules.CodeplexProject;component/Resources/Images/requirement.gif", UriKind.Relative))
        newFeatureTool.Command = controller.NotImplementedCommand
        newFeatureTool.CommandParameter = Nothing
        MenuToolBase.SetMenuItemDescription(newFeatureTool, "Submit a feature request about this application")
        m_NavigationService.AddTool(newFeatureTool, RegionNames.CodeplexProject_AppMenu_Feedback)

        ' Add Help Items
        m_NavigationService.AddLabelTool("View information about this application.", RegionNames.CodeplexProject_AppMenu_Help)
        m_NavigationService.AddButtonTool("Documentation", controller.NotImplementedCommand, Nothing, RegionNames.CodeplexProject_AppMenu_Help)
        m_NavigationService.AddButtonTool("Forum", controller.NotImplementedCommand, Nothing, RegionNames.CodeplexProject_AppMenu_Help)
    End Sub

    Private Function GteImage(ByVal uri As Uri) As ImageSource
        Dim stream As System.IO.Stream = Application.GetResourceStream(uri).Stream
        Dim bitmapDecoder As GifBitmapDecoder = New GifBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
        Return bitmapDecoder.Frames(0)
    End Function


End Class
